package com.woniuxy.dr_mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.dr_mall.entity.DrSpec;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author 张哲轩
 * @since 2021-08-11
 */
public interface DrSpecMapper extends BaseMapper<DrSpec> {

    @Select("select * from v_specs where productid=#{productId}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "id", property = "specVals", many = @Many(
                    fetchType = FetchType.LAZY,
                    select = "com.woniuxy.dr_mall.mapper.DrSpecValMapper.getSpecValsBySpecId"
            ))
    })
    List<DrSpec> getSpecs(int productId);

    @Select("select * from dr_spec ds,dr_category_spec dcs where dcs.specId = ds.id and dcs.categoryId=#{id}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "id", property = "specVals", many = @Many(
                    fetchType = FetchType.LAZY,
                    select = "com.woniuxy.dr_mall.mapper.DrSpecValMapper.getSpecValsBySpecId"
            ))
    })
    List<DrSpec> getByCategory(int categoryId);


}
